﻿using System;
using Glue;
using Glue.Converters;
using Xunit;

namespace GlueExamples
{
    namespace MappingBetweenDifferentTypes
    {
        public class When_mapping_between_different_types_using_built_in_converter
        {
            private class GuiPerson
            {
                public String Id { get; set; }
            }

            private class DomainPerson
            {
                public int Id { get; set; }
            }

            [Fact]
            public void Should_map_correctly()
            {
                var mapping = new Mapping<DomainPerson, GuiPerson>();
                mapping.AddConverter(Converting.BetweenIntAndString());
                mapping.AutoRelateEqualNames();

                var domainPerson = new DomainPerson { Id = 3 };
                var guiPerson = new GuiPerson();

                mapping.Map(domainPerson, guiPerson);

                Assert.Equal("3", guiPerson.Id);

            }
        }

        public class When_using_the_QuickConverter_for_custom_converting
        {
            [Fact]
            public void Doit()
            {
                var converter = new QuickConverter<int, bool>(fromInt => fromInt != 0, fromBool => fromBool?1:0);
                Assert.Equal(false, converter.MapTowardsRight(0));
                Assert.Equal(true, converter.MapTowardsRight(13));
                Assert.Equal(1, converter.MapTowardsLeft(true));
                Assert.Equal(0, converter.MapTowardsLeft(false));
            }
        }
    }
    
}
